package com.gsn.chooseRoom;

import java.util.ArrayList;

import javax.swing.text.View;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.gsn.dataCommon.ConfigModel;
import com.gsn.dataCommon.MakeRoomModel;
import com.gsn.dataCommon.UserData;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.poker.asset.FontTexture;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;

public class ChooseBet extends Group {

	public float width;
	public MakeRoomLayer makeRoom;

	public ChooseBet(float width, MakeRoomLayer makeRoom) {
		this.width = width;
		this.makeRoom = makeRoom;
	}

	public void init() {

		this.height = 0;
		PortalTexture portalTexture = PortalTexture.inst();
		ArrayList<String> arrayList = new ArrayList<String>();
		for (int i = 0; i < ConfigModel.channelModelList[ConfigModel.selectedChannel].bets.length; i++) {
			if (3 * ConfigModel.channelModelList[ConfigModel.selectedChannel].bets[i] <= UserData.gold) {
				arrayList.add(String.valueOf(ConfigModel.channelModelList[ConfigModel.selectedChannel].bets[i]));
			}
		}

		Label labelBet[] = new Label[arrayList.size()];

		for (int i = 0; i < arrayList.size(); i++) {
			Image image = new Image(portalTexture.textBoxWhite);
			portalTexture.scaleActor(image);
			image.width = this.width;
			addActor(image);
			labelBet[i] = new Label(arrayList.get(i), new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(0, 0, 0, 1)));
			addActor(labelBet[i]);
			labelBet[i].width = this.width;
			labelBet[i].y = i * image.height;
			labelBet[i].x = image.width * 0.05f;
			image.y = i * image.height;
			this.height = this.height + image.height;
			final int num = Integer.valueOf(arrayList.get(i));
			image.setClickListener(new ClickListener() {

				@Override
				public void click(Actor actor, float x, float y) {
					// TODO Auto-generated method stub
					PokerSound.playClick();
					MakeRoomModel.bet = num;
					hide();
					makeRoom.labelBetNumber.setText(ActorUtility.formatNumber(num));
				}
			});
		}

	}

	public void show() {
		clear();
		init();
		visible = true;
	}

	public void hide() {
		visible = false;
	}

}
